package com.qianxun;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.io.File;

/**
 * @author: huwei
 * @date: 2020/7/7 17:28
 * @version: 1.0.0
 */
@Order(-99999)
@WebListener
public class StartedInitListener implements ServletContextListener {
    @Value("${spring.resources.static-locations}")
    private String containerRootPath;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        String outerRootName = containerRootPath.split(",")[1].substring("file:".length());
        File root = new File(outerRootName);
        if(!root.exists()){
            if(!root.mkdirs()){
                System.err.println("创建外部仓库根目录失败,请自行创建：" + outerRootName);
            }
        }
    }
}
